//
//  main.cpp
//  DoubleLinkedList
//
//  Created by 종헌 백 on 12. 2. 28..
//  Copyright (c) 2012년 backssi1@naver.com. All rights reserved.
//
#include <iostream>

using namespace std;

class Node {
private:
    int key;
    Node* pPrev;
    Node* pNext;    
    
public:
    Node(int nTemp) { key = nTemp; pNext = NULL; };        //pNext = NULL;
    ~Node(){ };
    void setKey (int nTemp){ key = nTemp;};
    void setPrev (Node* pTemp) {pPrev = pTemp;};
    void setNext (Node* pTemp) {pNext = pTemp;};
    int getKey() { return key; };
    Node* getNext() { return pNext; };
    Node* getPrev() { return pPrev; );        
};

class List{
private:
    Node* pHead;
public:
    List();
    ~List();
    void insertNode ( int nTemp );
    void deleteNode ( int nTemp );
    void printOut ();
    
};

List :: List() 
{
    pHead = NULL;
}

List :: ~List() 
{
    Node* pCur;
    while (pHead) 
    {
        pHead = pHead -> getNext();
        delete pCur;
    }
}

void List :: printOut() 
{
    Node* pCur = pHead;
    while (pCur) 
    {
        cout << pCur -> getKey() << " ";
        pCur = pCur -> getNext();
    }
}

void List :: insertNode (int nTemp ) 
{
    Node* pNew = new Node (nTemp);
    Node* pCur = pHead;
    
    if (pHead) 
    {
        {
            while ( pCur -> getNext() )
                pCur = pCur -> getNext();
        }
        pCur -> setNext(pNew);
        ( pCur -> setNext(pNew) ) -> ;
    }
    else 
    {
        pHead = pNew;
    }
}

void List :: deleteNode(int nTemp) 
{
    Node* pCur = pHead;
    Node* pPre = NULL;
    while ( pCur && (pCur -> getKey() != nTemp) ) 
    {
        pPre = pCur;
        pCur = pCur -> getNext();
    }
    
    if(!pCur) 
    {
        return;
    }
    else 
    {
        pPre -> setNext( pCur -> getNext() );
        delete pCur;
    }
}

int main ()

{
    List numTable;
    
    numTable.insertNode(8);
    numTable.insertNode(20);
    numTable.insertNode(15);
    numTable.printOut();
    numTable.deleteNode(20);
    
    return 0;
}
